#pragma once
#include <vector>
#include <memory>
#include <boost\math\tools\fraction.hpp>
#include "TaylorSeries.h"
#include "Approximant.h"
#include "ProgressiveQD.h"

class CFraction : Approximant
{
public:
	CFraction(shared_ptr<TaylorSeries> pSeries, double c0);
	~CFraction(void);
		
	typedef std::pair<double, double> result_type;
	std::pair<double, double> operator()(); // TODO: make private by making continued_fraction_b a friend 

	void convert(); //puts the continued fraction in rational form
	int degree() const { return _degree; }
	virtual void build(unsigned int n);
	virtual double evaluate(double x);

	
private:
	double _c0;
	int _counter;
	int _degree;

	shared_ptr<vector<double> > _pnumeratorCoeffs;
	double _x;
	ProgressiveQD _pprogresiveQD;

	double a(unsigned int n);
	double b(unsigned int n); 

	double forwardRecurrence( double x );
	double backwardRecurrence( double x );
	double lentz( double x );

	Polynomial _numerator;
	Polynomial _denominator;

};

